.tabs {
  border: 1px solid var(--color-gray-200);
  border-radius: 0.375rem;

  &[data-orientation='vertical'] {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    box-shadow: inset -1px 0 var(--color-gray-200);
    min-width: 400px;
  }
}

.list {
  display: flex;
  position: relative;
  z-index: 0;
  padding: 0.25rem;
  gap: 0.25rem;
  box-shadow: inset 0 -1px var(--color-gray-200);

  &[data-orientation='vertical'] {
    flex-direction: column;
    padding: 0.5rem;
    box-shadow: inset -1px 0 var(--color-gray-200);
  }
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 0;
  margin: 0;
  outline: 0;
  background: none;
  appearance: none;
  color: var(--color-gray-600);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 500;
  user-select: none;
  white-space: nowrap;
  word-break: keep-all;
  padding-inline: 0.5rem;
  padding-block: 0;
  height: 1.5rem;

  &[data-orientation='vertical'] {
    height: 2rem;
  }

  &[data-active] {
    color: var(--color-gray-900);
  }

  &[data-disabled] {
    color: var(--color-gray-400);
  }

  @media (hover: hover) {
    &:not([data-disabled]):hover {
      color: var(--color-gray-900);
    }
  }

  &:focus-visible {
    position: relative;

    &::before {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: 0.25rem;
      outline: 2px solid var(--color-blue);
      outline-offset: -1px;
    }
  }
}

.indicator {
  flex-shrink: 0;
  position: absolute;
  z-index: -1;
  /* easier to debug than a single `inset:` */
  top: var(--active-tab-top);
  right: var(--active-tab-right);
  bottom: var(--active-tab-bottom);
  left: var(--active-tab-left);
  border-radius: 0.25rem;
  background-color: var(--color-gray-100);
  transition-property: left, right, top, bottom;
  transition-duration: 200ms;
  transition-timing-function: ease-in-out;

  &[data-orientation='vertical'] {
    /*
      handles an edge case when the tabs list is overflowing vertically,
      the indicator could be incorrectly sized when arrow keys change the tab
      and scroll the container at the same time
    */
    height: var(--active-tab-height);
  }

  &.elastic {
    &[data-activation-direction='right'] {
      transition:
        left 0.6s 0.1s,
        right 0.3s,
        top 0.3s,
        bottom 0.3s;
    }

    &[data-activation-direction='down'] {
      transition:
        top 0.6s 0.1s,
        bottom 0.3s;
    }

    &[data-activation-direction='left'] {
      transition:
        left 0.3s,
        right 0.6s 0.1s,
        top 0.3s,
        bottom 0.3s;
    }

    &[data-activation-direction='up'] {
      transition:
        top 0.3s,
        bottom 0.6s 0.1s;
    }
  }
}

.panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: 0;
  flex: 1 0 auto;

  &[data-hidden] {
    display: none;
  }

  &[data-orientation='horizontal'] {
    height: 8rem;
  }

  &:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: -1px;
    border-radius: 0.375rem;
  }
}
